home *** CD-ROM | disk | FTP | other *** search
-
- #ifndef __FILELOGGER_H_
- #define __FILELOGGER_H_
- /*
- Peon - Win32 Games Programming Library
- Copyright (C) 2002-2005 Erik Yuzwa
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with this library; if not, write to the Free
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- Erik Yuzwa
- peon AT wazooinc DOT com
- */
-
- #include "peonstdafx.h"
-
- #include "ISingleton.h"
-
-
- /**
- * The following are logging levels supported by the FileLogger.
- * The attempt is to use a mask approach to file logging. Let's say
- * you release the game using Peon to a customer. Since it's the
- * "production" (or "retail") version of your game, you should only really
- * capture critical errors (in order to not affect performance). Then you
- * can always get your customer to submit the log file should they experience
- * repeated problems.
- */
- #define PEON_LOG_INFO 0x0001
- #define PEON_LOG_DEBUG 0x0002
- #define PEON_LOG_ERROR 0x0004
- #define PEON_LOG_FATAL 0x0008
-
-
- namespace peon {
-
- /**
- *
- * This object is just used to output any needed log messages to
- * a file. We COULD make this fancier (like a primitive Log4J
- * solution) by perhaps creating a LogInterface superclass, which
- * we can then derive FileLogger from. This would then allow us
- * to also create an SMTPLogger or HTMLLogger for example (to output
- * our log messages over SMTP or into a nice and purty HTML document).
- *
- * I made derived it from the ISingleton object in order to be
- * accessible pretty much everywhere in our game and/or Peon.
- */
- class PEONMAIN_API FileLogger : public ISingleton<FileLogger>
- {
-
- protected:
-
- /** the file handle */
- std::ofstream m_log_file;
-
- /** name of the file */
- String m_strLogName;
-
- /** our logging level or filter */
- int m_logging_level;
-
- protected:
-
- /**
- * This method is responsible for writing out text to our
- * logfile
- * @param String - our desired text to append
- * @return void
- */
- void writeToLogStream(const String& strText);
-
-
- public:
-
- /**
- * Constructor
- * @param log_flag - the logging filter level
- */
- FileLogger( int log_flag = PEON_LOG_DEBUG );
-
- /**
- * Destructor
- */
- ~FileLogger();
-
- /** Override standard Singleton retrieval.
- @remarks
- Why do we do this? Well, it's because the Singleton
- implementation is in a .h file, which means it gets compiled
- into anybody who includes it. This is needed for the
- Singleton template to work, but we actually only want it
- compiled into the implementation of the class based on the
- Singleton, not all of them. If we don't change this, we get
- link errors when trying to use the Singleton-based class from
- an outside dll.
- @par
- This method just delegates to the template version anyway,
- but the implementation stays in this single compilation unit,
- preventing link errors.
- */
- static FileLogger& getSingleton(void);
-
- /** Override standard Singleton retrieval.
- @remarks
- Why do we do this? Well, it's because the Singleton
- implementation is in a .h file, which means it gets compiled
- into anybody who includes it. This is needed for the
- Singleton template to work, but we actually only want it
- compiled into the implementation of the class based on the
- Singleton, not all of them. If we don't change this, we get
- link errors when trying to use the Singleton-based class from
- an outside dll.
- @par
- This method just delegates to the template version anyway,
- but the implementation stays in this single compilation unit,
- preventing link errors.
- */
- static FileLogger* getSingletonPtr(void);
-
- /**
- * This method simply opens the file handle and prepares the
- * log file for writing
- * @param std::string - our desired filename
- * @return bool - true if we succeeded, error code otherwise
- */
- bool openLogStream(const String& strName);
-
- /**
- * This method is responsible for shutting down our logging
- * and closing any file handles
- * @param void
- * @return void
- */
- void closeLogStream(void);
-
- /**
- * This method logs a string setting it to "Info" mode. It then
- * compares it with the internal log setting to see if it should
- * be recorded or not.
- * @param strObject - object making logging call
- * @param strText - text to output
- */
- void logInfo ( const String& strObject, const String& strText);
-
- /**
- * This method logs a string setting it to "Debug" mode. It then
- * compares it with the internal log setting to see if it should
- * be recorded or not.
- * @param strObject - object making logging call
- * @param strText - text to output
- */
- void logDebug(const String& strObject, const String& strText);
-
- /**
- * This method logs a string setting it to "Error" mode. It then
- * compares it with the internal log setting to see if it should
- * be recorded or not.
- * @param strObject - object making logging call
- * @param strText - text to output
- */
- void logError(const String& strObject, const String& strText);
-
- /**
- * This method logs a string setting it to "Fatal" mode. It then
- * compares it with the internal log setting to see if it should
- * be recorded or not.
- * @param strObject - object making logging call
- * @param strText - text to output
- */
- void logFatal( const String& strObject, const String& strText);
-
-
-
- };
- }
-
- #endif
-